package dao

import (
	"gitee.com/legend9999/publisher/modle"
	"log"
)

type BookStatusDAO int

func (b *BookStatusDAO) Save(status *modle.BookStatus) error {
	db := DB.Save(status)
	if err := db.Error; err != nil {
		log.Printf("update status%+v err:%s", status, err)
		return err
	}
	return nil
}
func (b *BookStatusDAO) Query(bookID int64, status modle.Status) (*modle.BookStatus, error) {
	var book modle.BookStatus
	if err := DB.Where("book_id = ? and status = ?", bookID, status).First(&book).Error; err != nil {
		log.Printf("query book bookID:%+d status:%d err:%s", bookID, status, err)
		return nil, err
	}
	return &book, nil
}
func (b *BookStatusDAO) QueryList(bookID int64) ([]*modle.BookStatus, error) {
	var book []*modle.BookStatus
	if err := DB.Where("book_id = ?", bookID).Find(&book).Error; err != nil {
		log.Printf("query book bookID:%+d err:%s", bookID, err)
		return nil, err
	}
	return book, nil
}
